<template>
    <view class="image-repair-container">
      <view class="image-container">
        <image :src="originalImage" alt="修复前" class="image" mode="aspectFit"></image>
        <view class="image-label">修复前</view>
      </view>
    
      <view class="image-container">
        <image :src="processedImage" alt="修复后" class="image" mode="aspectFit"></image>
        <view class="image-label">修复后</view>
      </view>
    
      <!-- 操作按钮 -->
      <view class="button-container">
        <button class="btn btn-repair" @click="startProcessing">开始处理</button>
		<button class="btn btn-select" @click="download">下载结果</button>
      </view>
    </view>
</template>

<script>
import { repair, enhance } from '../../api/image.js'
export default {
    data() {
        return {
            originalImage: '',
            processedImage: '',
			step: 1,
			loading: false,
			title: '',
			operation: ''
        };
    },
    onLoad(options) {
		console.log(options);
        this.originalImage = options.imagePath;
		this.title = options.title || '图像修复'
		this.operation = options.key
		uni.setNavigationBarTitle({
			title: this.title
		});
    },
    methods: {
		// 处理图像
        async startProcessing() {
			this.step = 1;
			this.loading = true;
			this.processedImage = '';
			setTimeout(()=>{
				if(this.operation === 'repair') {
					this.processedImage = 'http://qiniu-image.akfang.cn/04670b3a-89ed-40b1-8783-feb9a6eabcee_MaryLi-1_mask_repair.png'
				} else {
					this.processedImage = 'http://qiniu-image.akfang.cn/test/10351744447535_.pic.jpg'
				}
				this.step = 2;
				this.loading = false;
			})
			
    //         try {
    //             const formData = {
				// 	img: this.originalImage,
				// 	operation: this.operation
				// };
    //             // 发送请求到后端处理图片
				// let api = null;
    //             if(this.operation === 'repair') {
				// 	api = repair;
				// } else if(this.operation === 'enhance') {
				// 	api = enhance;
				// }
				// console.log(api, formData);
				// if(typeof api === 'function') {
				// 	api(this.originalImage, formData).then(res=>{
				// 		if(res.code === 200) {
				// 			this.step = 2;
				// 			this.loading = false;
				// 			this.processedImage = res.imgUrl;
				// 		}
				// 	})
				// }	
    //         } catch (error) {
    //             console.error('图片处理失败:', error);
    //         }
        },
		// 下载结果
		download() {
			console.log("download");
		}
	}
};
</script>

<style lang="scss">
.image-repair-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background-color: #f8f8f8;
  padding: 0 16px;
  
  .image-container {
    width: 90%;
	flex: 1;
    margin-bottom: 16px;
    border: 1px solid #eee;
    border-radius: 8px;
    overflow: hidden;
    position: relative;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
    
    .image {
      width: 100%;
      object-fit: contain;
    }
    
    .image-label {
      position: absolute;
      bottom: 0;
      left: 0;
      width: 100%;
      background-color: rgba(0, 0, 0, 0.7);
      color: #fff;
      text-align: center;
      padding: 6px 0;
      font-size: 14px;
      font-weight: 500;
    }
  }
  
  .button-container {
    display: flex;
    justify-content: space-around;
    width: 90%;
    margin: 14px 0;
    
    .btn {
      padding: 4px 10px;
      border: none;
      border-radius: 6px;
      cursor: pointer;
      font-size: 16px;
      font-weight: 500;
      transition: all 0.2s ease;
      box-shadow: 0 2px 4px rgba(0,0,0,0.1);
      
      &:active {
        transform: scale(0.96);
      }
    }
    
    .btn-select {
      background-color: #4CAF50;
      color: white;
    }
    
    .btn-repair {
      background-color: #2196F3;
      color: white;
    }
  }
  
  .placeholder {
    height: 220px;
    background-color: #f5f5f5;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    color: #999;
  }
}
</style>